﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using Projectmanagement.Utl;
using Projectmanagement.Entity;

namespace ProjectManagement.Models
{
    public class _Task : EntityBase
    {


        //3	未启动		0
        //4	进行中		30
        //5	暂停		10
        //6	取消		-1
        //7	请审核		90
        //8	通过		100
        //9	求助		20
        //11	失败		-10
        public const int NoStart = 0;
        public const int InProgress = 30;
        public const int Pause = 10;
        public const int Cancel = -1;
        public const int NeedApprove = 90;
        public const int Pass = 100;
        public const int Fail = -10;

        [Display(Name = "任务状态")]
        public string TaskStateName { get; set; }
        public int TaskStateCode { get; set; }
        [Display(Name = "任务状态"), Required]
        public int? TaskStateID { get; set; }
        [Display(Name = "所属项目"), Required]
        public int? ProjectID { get; set; }

        [Display(Name = "所属项目"), Required]
        public string ProjectCode { get; set; }

        [Display(Name = "所属里程碑")]
        public int? MilestoneID { get; set; }

        [Display(Name = "任务发放人")]
        public string Assinger { get; set; }

        [Display(Name = "实际完成时间")]
        public DateTime? FinishDate { get; set; }

        [Display(Name = "任务知会")]
        public string Notify { get; set; }


        [Display(Name = "任务名称"), Required]
        public string Name { get; set; }

        //[Display(Name = "倒推天数"), Required]
        //public int DateCount { get; set; }

        [Display(Name = "开始时间"), Required, DisplayFormat(DataFormatString = "{0:d}")]
        public DateTime StartDate { get; set; }

        [Display(Name = "结束时间"), Required, DisplayFormat(DataFormatString = "{0:d}")]
        public DateTime EndDate { get; set; }

        [Display(Name = "任务执行人"), Required]
        public string Owners { get; set; }

        [Display(Name = "总天数")]
        public int Duration { get { return (EndDate - StartDate).Days; } }

        [Display(Name = "内容")]
        public string Content { get; set; }

        [Display(Name = "知识库链接")]
        public string KMLinks { get; set; }

        [Display(Name = "可交付成果")]
        public string Deliverables { get; set; }

        //[Display(Name = "完成度"), Range(0,1),Required]
        //public double Complement { get; set; }

        public IEnumerable<SelectListItem> GetProjectSelectListItems()
        {

            var selectList = Helpers.GetUserProjects().ToList().Select(a => new SelectListItem
            {
                Text = a.ProjectDisplayName,
                Value = a.ID.ToString()
            });
            return selectList;
        }

        public string Ttype { get; set; }

        public string FinishPer
        {
            get
            {
                return this.FinishDate == null
                    ? ((DateTime.Now - this.StartDate).Days + "/" + Duration)
                    : ((Convert.ToDateTime(this.FinishDate) - this.StartDate).Days + "/" + Duration);
            }
        }

        public string GetTemp
        {
            get
            {
                return DateTime.Now.ToString();
            }
        }

        [Display(Name = "任务编号")]
        public string TaskCode { get; set; }
    }

    public class _TaskTemplate : EntityBase
    {
        [Display(Name = "倒推天数"), Required]
        public int DateCount { get; set; }

        [Display(Name = "总天数"),Required]
        public int Duration { get; set; }

        [Display(Name = "默认角色")]
        public int? RolePMID { get; set; }

        [Display(Name = "里程碑"), Required]
        public int? MilestoneID { get; set; }
        //[Display(Name = "完成度"), Range(0, 1)]
        //public double Complement { get; set; }

        [Display(Name = "任务默认选中"), Required]
        public bool IsDefault { get; set; }

        [Display(Name = "任务名称"), Required]
        public string Name { get; set; }

        [Display(Name = "任务描述"), Required]
        public string Content { get; set; }

        [Display(Name = "任务执行角色"), Required]
        public string RolePM { get; set; }

        [Display(Name = "知识库链接")]
        public string KMLinks { get; set; }

        [Display(Name = "可交付成果")]
        public string Deliverables { get; set; }

    }


    public class _TaskComment : EntityBase
    {
        [Display(Name = "提交人"), Required]
        public string Submitter { get; set; }

        [Display(Name = "内容"), Required]
        public string Contents { get; set; }

        [Display(Name = "评论日期"), Required]
        public DateTime CommentDate { get; set; }

        public int? TaskID { get; set; }

        public Task GetTask
        {
            get
            {
                return CH.DB.Tasks.Find(this.TaskID);
            }
        }
    }

    public class _ImportModel
    {
        public int? ProjectID { get; set; }

        public string Templates { get; set; }

        public IEnumerable<_TaskTemplate> TemplateList { get; set; }
    }
}